- item ||= f.object

.form-field.role-row.role-row--merchandise
  .item-block-role.item-block-role--purchase-invoice
    :ruby
      options = {
        label: :merchandise.tl,
        source: {scope: :purchaseables},
        input_html: {
          class: "invoice-variant",
          data: {
            variant_of_deal_item: {
              url: detail_backend_product_nature_variant_path("RECORD_ID", mode: :last_purchase_item)
            },
            product_of_delivery_item: {
              url: backend_product_nature_variant_path("RECORD_ID", format: :json)
            },
            required: true
          }
        }
      }
    = f.referenced_association(:variant, **options)
    .annotation-logo
      - if f.object.annotation.blank?
        = link_to("#", data: { annotate: ".annotate", use_closest: "tbody" }, title: :add_annotation.tl) do
          %i.annotation-field

    - display = ""
    - display = "display: none;" unless item && item.variant && item.variant.depreciable?
    .fixed-asset-fields{style: display, data: {"when-item": "depreciable", "when-display-value": 'true'}}
      = f.input :fixed

      - display = "display: none;" unless item.fixed
      .assets{style: display}
        = f.input :preexisting_asset, label: :asset_exists.tl

        - display_existing_asset = "display: none;" unless item.preexisting_asset
        .existing_asset{style: display_existing_asset}
          = f.referenced_association :fixed_asset, source: :drafts

        - display_new_asset = "display: none;" if item.preexisting_asset
        .new_asset{style: display_new_asset}
          = f.referenced_association(:depreciable_product)

  .item-block-quantity
    .storing-fields
      .storing-calculation
        .storing-conditionning
          = f.input :conditionning, wrapper: :append do
            = f.input_field :conditionning , class: "quantity invoice-conditionning conditionning", data: { trade_component: 'conditionning' }
            %span.add-on.item-population-unit-name
              = variant.unit_name.or_else('unité')
        %div.control-group.multiplicator X
        .storing-conditionning-quantity.storing-conditionning-quantity--merchandise
          = f.input :conditionning_quantity, wrapper: :append do
            = f.input_field :conditionning_quantity , class: "quantity invoice-conditionning-quantity conditionning-quantity", data: { trade_component: 'conditionning_quantity'}
        %div.control-group.multiplicator= "="
        .storing-quantifier
          = f.input :quantity, wrapper: :append do
            = f.input_field :quantity, class: "invoice-quantity storing-quantity", placeholder: '0', size: 7, data: {trade_component: "quantity", required: true}
            %span.add-on.item-population-unit-name
              = variant.unit_name.or_else('unité')

      %div.current-stock
        .merchandise-current-stock
          %span.stock-label= :current_stock.tl
          %span.stock-value= f.object.decorate.merchandise_current_stock
          %span.stock-unit= f.object.decorate.merchandise_stock_unit

.annotation-section
  .annotation-field
    - attrs = {}
    - attrs[:style] = "display: none" if f.object.annotation.blank?
    .annotate{attrs}= f.input(:annotation, wrapper: :nested, input_html: { class: "annotation" })
